package com.freak.wanandroid.model.home.activity;

import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.freak.wanandroid.R;
import com.freak.wanandroid.base.activity.BaseActivity;
import com.freak.wanandroid.util.ToolUtils;
import com.freak.wanandroid.util.WebViewUtil;

/**
 * Created by 74099 on 2018/7/17.
 */
public class BannerDetailAct extends BaseActivity {
    private LinearLayout mLlBannerDetail;
    private WebView mWebView;
    private String mUrl;
    private String mTitle;
    private ProgressBar mProgressBar;
    private LinearLayout mLlWebError;


    //    /**
//     * 断网重连
//     * @param networkType
//     */
//    @Override
//    public void onNetConnected(NetworkType networkType) {
//        super.onNetConnected(networkType);
//        ll_web_error.setVisibility(View.GONE);
//        ll_banner_detail.setVisibility(View.VISIBLE);
//        WebViewUtil.getInstance().initWebView(mWebView,this,url,mProgressBar);
//    }

    @Override
    protected int getLayout() {
        return R.layout.act_banner_detail;
    }

    @Override
    protected void initEventAndData() {
        mLlBannerDetail = findViewById(R.id.ll_banner_detail);
        mUrl = getIntent().getStringExtra("url");
        mTitle = getIntent().getStringExtra("title");
//        setTitleTx(title);
        mLlBannerDetail = findViewById(R.id.ll_banner_detail);
        mLlWebError = findViewById(R.id.ll_web_error);
        mProgressBar = findViewById(R.id.progressBar1);
        mWebView = new WebView(getApplicationContext());
        mWebView.setBackgroundColor(0);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        mWebView.setLayoutParams(params);
        mLlBannerDetail.addView(mWebView);
        if (!ToolUtils.isConnected(this)) {
            mLlWebError.setVisibility(View.VISIBLE);
            mLlBannerDetail.setVisibility(View.GONE);
        } else {
            mLlWebError.setVisibility(View.GONE);
            mLlBannerDetail.setVisibility(View.VISIBLE);
            WebViewUtil.getInstance().initWebView(mWebView, this, mUrl, mProgressBar);
        }

    }

    @Override
    protected void onDestroyRelease() {
        WebViewUtil.cleanWebView(mWebView);
        mWebView = null;
    }

    @Override
    protected void initView() {

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        if (WebViewUtil.onBackPressed(mWebView)) {
            super.onBackPressed();
        }
    }
}
